//
//  ZYSocketMessageUtils.m
//  YiLin
//
//  Created by Zyark on 2018/7/5.
//  Copyright © 2018年 Zyark. All rights reserved.
//

#import "ZYSocketMessageUtils.h"
#import "RHSocketService.h"
#import "DeviceCommunicate.pbobjc.h"

@implementation ZYSocketMessageUtils
+(void)setDeviceWithMac:(NSString *)mac andParams:(NSDictionary *)params{
    device_communicate *message = [[device_communicate alloc] init];
    RHSocketPacketRequest *req = [[RHSocketPacketRequest alloc] init];
    message.module = 100;
    message.cmd = 2;
    message.sid = [ZYConfig loginToken];
    message.userId = [ZYConfig userId];
    message.macAddress = mac;
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:params];
    [dict setObject:@0 forKey:@"lockStatus"];
    [dict setObject:@1 forKey:@"powerStatus"];
    message.jsonStr = [dict modelToJSONString];
    NSLog(@"json:%@",message.jsonStr);
    req.object = [message data];
    [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationSocketPacketRequest object:req];
}

+(void)setDeviceStatusWithMac:(NSString *)mac andParams:(NSDictionary *)params{
    device_communicate *message = [[device_communicate alloc] init];
    RHSocketPacketRequest *req = [[RHSocketPacketRequest alloc] init];
    message.module = 100;
    message.cmd = 2;
    message.sid = [ZYConfig loginToken];
    message.userId = [ZYConfig userId];
    message.macAddress = mac;
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:params];
    message.jsonStr = [dict modelToJSONString];
    NSLog(@"json:%@",message.jsonStr);
    req.object = [message data];
    [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationSocketPacketRequest object:req];
}

+(void)setDeviceWithMac:(NSString *)mac andParams:(NSDictionary *)params andCmd:(int)cmd{
    device_communicate *message = [[device_communicate alloc] init];
    RHSocketPacketRequest *req = [[RHSocketPacketRequest alloc] init];
    message.module = 100;
    message.cmd = cmd;
    message.sid = [ZYConfig loginToken];
    message.userId = [ZYConfig userId];
    message.macAddress = mac;
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:params];
    [dict setObject:@0 forKey:@"lockStatus"];
    [dict setObject:@1 forKey:@"powerStatus"];
    message.jsonStr = [dict modelToJSONString];
    NSLog(@"json:%@",message.jsonStr);
    req.object = [message data];
    [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationSocketPacketRequest object:req];
}

@end
